using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class ChiSo_PhieuKhamDVRepository
	{
		public static List<ChiSo_PhieuKhamDV> SelectAll()
		{
			return DataContext.Instance.ChiSo_PhieuKhamDV.ToList();
		}

		public static ChiSo_PhieuKhamDV SelectByID(int macspkdv)
		{
			return DataContext.Instance.ChiSo_PhieuKhamDV.FirstOrDefault(item => item.MaCSPKDV == macspkdv );
		}

		public static bool Insert(ChiSo_PhieuKhamDV obj)
		{
			try
			{
				DataContext.Instance.ChiSo_PhieuKhamDV.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int macspkdv)
		{
			try
			{
				var delitem = DataContext.Instance.ChiSo_PhieuKhamDV.FirstOrDefault(item => item.MaCSPKDV == macspkdv );
				DataContext.Instance.ChiSo_PhieuKhamDV.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<ChiSo_PhieuKhamDV> RetrieveByID(int macspkdv)
		{
			return (from item in DataContext.Instance.ChiSo_PhieuKhamDV where  item.MaCSPKDV == macspkdv  select item).ToList();
		}

		public static List<ChiSo_PhieuKhamDV> SelectByMaPKDV(int mapkdv)
		{
			var lstItem = (from item in DataContext.Instance.ChiSo_PhieuKhamDV where item.MaPKDV == mapkdv select item).ToList();
			return lstItem;
		}

		public static List<ChiSo_PhieuKhamDV> SelectByMaCS(string macs)
		{
			var lstItem = (from item in DataContext.Instance.ChiSo_PhieuKhamDV where item.MaCS == macs select item).ToList();
			return lstItem;
		}

	}
}